<?php
//set_time_limit('180');
//header('Content-type: text/html;charset=utf-8');
//$rss_url = '';
//$content = file_get_contents($rss_url);
//  file_put_contents($filepath, $content);  //缓存列表页到.txt中
//  $rss     =  simplexml_load_string($content,'SimpleXMLElement',LIBXML_NOCDATA);
$rss_url = 'http://vanillacloud.blogcn.com/feed';
$filepath = 'blog.txt';
if (file_exists($filepath) && filemtime($filepath) + 8800 > time()) { //判断此文件是否为半小时更新的,如果超过半小时,更新文件
    $content = file_get_contents($filepath);
	//$content = preg_replace('#<description>(.*)</description>.*<content:encoded>(.*)</content:encoded>#is','<description>\\2</description>',$content);
	//preg_match_all('#<description><!\[CDATA[\w\W]*<content:encoded><!\[CDATA([\w\W]*)</content:encoded>#iU',$content,$matches);
	//var_dump($matches);die();
	$content = preg_replace('#<description><!\[CDATA[\w\W]*<content:encoded><!\[CDATA([\w\W]*)</content:encoded>#iU','<description><![CDATA\\1</description>',$content);
	echo $content;
    $rss  = simplexml_load_string ($content,'SimpleXMLElement',LIBXML_NOCDATA);
}else{
    $content = file_get_contents($rss_url);
    $content = mb_convert_encoding ( $content , 'UTF-8' ,'auto');
    file_put_contents('blog.txt',$content);
    $rss =  simplexml_load_string($content,'SimpleXMLElement',LIBXML_NOCDATA);
}

echo '<pre>';
print_r($rss);
//echo $content;
?>